; small twist / TLR
; original design by Street Tuff

	processor 6502
	org	$0801

s:
	dc.w	link
	dc.w	0
	dc.b	$9e,"2059",0
link:
; 	dc.w	0
	ldx	#0
	stx	$d020
	stx	$d021
lp1:
	lda	pack-1,x
	sta	unpack-1,x
	lsr
	lsr
	lsr
	lsr
	adc	#10
	sta	unpack+24-1,x
	dex
	bne	lp1
;C=0, X=0
lp2:
	lda	#31
	eor	sine,x		; calculate (31-sine)
	sta	sine+16,x
;	clc
	adc	#33-31		; calculate (33-sine)
	sta	sine2,x
	inx
	bne	lp2

	jsr	$e544

lp3:
	jsr	plot
	jsr	plot

	jsr	$aad7		; CR/LF

	inx
	txa
	and	#$0f
	bne	lp3
	lda	#$18
	jsr	swap
	bne	lp3

plot:
psm2:
	lda	sine,x
	sta	$d3
	ldy	#7
plp1:
psm1:
	lda	ctab-1,y
	sta	$0286
	lda	#$e6
	jsr	$ffd2
	dey
	bne	plp1
pex1:
	lda	#$08
swap:
	eor	psm1+1
	sta	psm1+1
	lda	#>[sine2^sine]
	eor	psm2+2
	sta	psm2+2
	rts

	mac	pd
	dc.b	{1} | [[{2}-10-[[{1}>>3]&1]]&$0f] << 4
	endm

pack:
	pd	$6,$9
	pd	$e,$8
	pd	$3,$a
	pd	$f,$f
	pd	$3,$a
	pd	$e,$8
	pd	$6,$9
	pd	$0,$0
	pd	$9,21
	pd	$8,21
	pd	$f,21
	pd	$f,20
	pd	$f,20
	pd	$8,19
	pd	$9,18
	pd	$0,17
	pd	$6,16
	pd	$e,14
	pd	$f,13
	pd	$f,12
	pd	$f,11
	pd	$e,11
	pd	$6,10
	pd	$0,10
e:
	echo	e-s+2

unpack	equ	$08a1		
ctab	equ	unpack
;	dc.b	$6,$e,$3,$f,$3,$e,$6,0 
;	dc.b	$9,$8,$f,$f,$f,$8,$9,0
;	dc.b	$6,$e,$f,$f,$f,$e,$6,0 
;	dc.b	$9,$8,$a,$f,$a,$8,$9,0

sine	equ	ctab+$20
;	dc.b	21,21,21,20,20,19,18,17,16,14,13,12,11,11,10,10
sine2	equ	sine+512
